import java.security.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

public class peer
{
	public static void main(String[] argv) throws Exception
	{
		String data = "file_name="+URLEncoder.encode(SHA1("a.txt"), "UTF-8") + "&port=" + URLEncoder.encode("3739", "UTF-8");
		data += "&uploaded=" + URLEncoder.encode("0", "UTF-8") + "&downloaded=" + URLEncoder.encode("0", "UTF-8")+ "&left=" + URLEncoder.encode("0", "UTF-8") + "&event=" + URLEncoder.encode("started", "UTF-8");

		URL url = new URL("http://167.205.35.12:8080/?"+data);
		URLConnection conn = url.openConnection();

		BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
		String line;
		while ((line = rd.readLine()) != null)
		{
			System.out.println(line);
		}
		
		rd.close();
	}
	
	public static String SHA1(String input)
	{
		try {
			MessageDigest md = MessageDigest.getInstance("SHA1");
			md.update(input.getBytes()); 
			byte[] output = md.digest();
			return bytesToHex(output);
		}
		catch (Exception e) {
			System.out.println("Exception: "+e);
			return "Exception: "+e;
		}
	}
	
	public static String bytesToHex(byte[] b)
	{
		char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7',
						   '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
		StringBuffer buf = new StringBuffer();
		for (int j=0; j<b.length; j++)
		{
			buf.append(hexDigit[(b[j] >> 4) & 0x0f]);
			buf.append(hexDigit[b[j] & 0x0f]);
		}
		return buf.toString();
	}
	
	public static String bytesToHex(String b)
	{
		char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7',
						   '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
		StringBuffer buf = new StringBuffer();
		int i;
		for (int j=0; j<b.length(); j++)
		{
			i = (int)b.charAt(j);
			buf.append(hexDigit[(i >> 4) & 0x0f]);
			buf.append(hexDigit[i & 0x0f]);
		}
		return buf.toString();
	}
}